//
//  ResultProgressCell.m
//  iiecg
//
//  Created by Shanlin on 2017/3/1.
//  Copyright © 2017年 Boundary Technology. All rights reserved.
//

#import "ResultProgressCell.h"
#import "ProgressView.h"
#import "ReportDescPop.h"

@interface ResultProgressCell()


@property (weak, nonatomic) IBOutlet UILabel *contentLabel;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *contentWConstraint;
@property (weak, nonatomic) IBOutlet UIImageView *problemImageView;
@property (weak, nonatomic) IBOutlet UIButton *descButton;

@property(nonatomic,strong) ResultProgressBean *bean;

@property (weak, nonatomic) IBOutlet UILabel *valueLabel;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *valueWConstraint;

@property (nonatomic,strong) ProgressView *progressView;//
@property (weak, nonatomic) IBOutlet UIView *progressBGView;
@property (weak, nonatomic) IBOutlet UILabel *status1Label;
@property (weak, nonatomic) IBOutlet UILabel *status2Label;
@property (weak, nonatomic) IBOutlet UILabel *status3Label;

@end

@implementation ResultProgressCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
    self.selectionStyle = UITableViewCellSelectionStyleNone;
    self.problemImageView.image = [UIImage imageNamed:@"ecg_img_problem"];
    [self.descButton setImage:[UIImage imageNamed:@"ecg_haveNoPro"] forState:UIControlStateNormal];
    [self.progressBGView addSubview:self.progressView];
    self.status1Label.font = [UIFont systemFontOfSize:13];
    self.status2Label.font = [UIFont systemFontOfSize:13];
    self.status3Label.font = [UIFont systemFontOfSize:13];
    self.valueLabel.font = self.status1Label.font;
}


-(ProgressView *)progressView
{
    if (!_progressView) {
        _progressView  = [[ProgressView alloc] initWithFrame:CGRectMake(0, 0, KScreenW - 32, 23) colors:@[ECG_COLOR_BLUE,ECG_COLOR_GREEN,ECG_COLOR_YELLOW,ECG_COLOR_RED]];
    }
    return _progressView;
}

-(void)setBean:(ResultProgressBean *)bean{
    __weak typeof(self)weakSelf = self;
    _bean = bean;
    [IKPublicUtil runOnMainThread:^{
        weakSelf.problemImageView.hidden = !bean.isProblem;
        weakSelf.contentWConstraint.constant = [bean widthForString:bean.text fontSize:scale(15)];
        weakSelf.contentLabel.text = bean.text;
        weakSelf.contentLabel.textColor = COLOR_BLACK_6F6F6F;
        weakSelf.progressView.progress = bean.progress;
        
        weakSelf.valueWConstraint.constant = [bean widthForString:bean.value fontSize:scale(15)];
        weakSelf.valueLabel.text = bean.value;
    }];
    
}

+(instancetype)createWith:(UITableView *)tableView bean:(ResultProgressBean *)bean
{
    static NSString *ID = @"ResultProgressCell";
    ResultProgressCell *cell = [tableView dequeueReusableCellWithIdentifier:ID];
    if (cell == nil) {
        cell = [[[NSBundle mainBundle]loadNibNamed:ID owner:nil options:nil] lastObject];
    } else {
        while ([cell.contentView.subviews lastObject] != nil) {
            [(UIView *)[cell.contentView.subviews lastObject] removeFromSuperview];
        }
    }
    
    cell.bean = bean;
    cell.status1Label.text = INTERNATIONAL(@"string_depressed");
    cell.status2Label.text = INTERNATIONAL(@"string_good");
    cell.status3Label.text = INTERNATIONAL(@"string_anxious");
    return cell;

}

- (IBAction)descAction:(UIButton *)sender {
    
    [[ReportDescPop createWith:self.bean.descTitle desc:self.bean.desc] show:YES];
}


@end
